import axios from '@ohos/axios'
import Image from '../viewModel/Images'
import Invoice from '../viewModel/Invoice'
// let baseUrl= '10.2.2.108'
let baseUrl= '192.168.43.254'
class ImageModel{
  //查询
  getImageList():Promise<Image[]>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'GET',
        url:'http://'+baseUrl+':8080/image/listImage',
        params:{
          uid:AppStorage.Get('uid')
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('查询失败')
      })
    })
  }
  //新增
  insertImage(image:Image):Promise<number>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'POST',
        url:'http://'+baseUrl+':8080/image/insertImage',
        data:{
          uid:AppStorage.Get('uid'),
          url:image.url,
          isdelete:0
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('失败')
      })
    })
  }

}
const imageModel = new ImageModel();
export default imageModel as ImageModel;


